package exception_;

import java.util.Scanner;

public class TryCatchExercise01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = 0;
        boolean flag = true;
        while (true){
            System.out.print("请输入字符串：");
            String num = scanner.nextLine();
            try {
                n = Integer.parseInt(num);
                flag = false;
            } catch (NumberFormatException e) {
                System.out.println("出现异常：" + e.getMessage());
            }
            if (!flag){
                System.out.println("转换数字成功：" + n);
                break;
            }
        }
    }
}
